package com.mogujie.tt.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.mogujie.tt.R;
import com.mogujie.tt.ui.widget.QuanzQzMyPhotoDetail;

import java.util.List;

/**
 * Created by Administrator on 2015/11/12.
 */
public class MypotoListitemAdapter extends BaseAdapter {
    private Context context;
    private List<QuanzQzMyPhotoDetail> list = null;
    private QuanzQzMyPhotoDetail hotodetail;
    private MypotoGridViewitemAdapter adapter;


    public MypotoListitemAdapter(Context context){
        this.context = context;
    }

    @Override
    public boolean areAllItemsEnabled() {
        return false;
    }

    @Override
    public boolean isEnabled(int position) {
        return false;
    }
    @Override
    public int getCount() {
        return list == null ? 0 : list.size();
    }

    @Override
    public Object getItem(int i) {
        return list == null ? null : list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }
    public void setData(List<QuanzQzMyPhotoDetail> list) {
        this.list = list;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        try {
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(
                    R.layout.quanz_qz_myphoto_item, null);
            holder = getHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
       // GpC(holder);
        if (list != null) {
            hotodetail = list.get(position);
            hotodetail.position = position;
            bindData(holder);
        }
        return convertView;
        }catch (Exception e){
            System.out.println("1111111MypotoListitemAdapter   " + e.getMessage());
        }
        return null;
    }

    private void GpC(ViewHolder holder) {
        View mHeadViw = LayoutInflater.from(context).inflate(R.layout.quanz_qz_myphoto_item_f, null);
        View LL_O = mHeadViw.findViewById(R.id.LL_image);
        LL_O.setVisibility(View.VISIBLE);
        View LL_te = mHeadViw.findViewById(R.id.LL_text);
        LL_te.setVisibility(View.GONE);
        holder.plistview.addHeaderView(mHeadViw, null, false);
    }


    private void bindData(ViewHolder holder) {

        if (hotodetail == null)
            return;

        if (hotodetail.position==0){
            holder.ptvtime1.setText(hotodetail.getTime0());
            holder.ptvtime2.setText(hotodetail.getTime1());
        }else {
            holder.ptvtime1.setText(hotodetail.getTime0());
            holder.ptvtime2.setText(hotodetail.getTime1() + "月");
        }
        adapter=new MypotoGridViewitemAdapter(context,hotodetail.getList());
        holder.plistview.setAdapter(adapter);
        holder.plistview.setFocusableInTouchMode(true);
        holder.plistview.setFocusable(false);
    }

    private ViewHolder getHolder(View convertView) {
        ViewHolder holder = new ViewHolder();
        holder.ptvtime1 = (TextView) convertView.findViewById(R.id.tvtime1);
        holder.ptvtime2 = (TextView) convertView.findViewById(R.id.tvtime2);
        holder.plistview = (ListView) convertView.findViewById(R.id.photolistview);
        return holder;
    }

    class ViewHolder {
        public TextView ptvtime1;
        public TextView ptvtime2;
        public ListView plistview;
    }

}
